import { rankMgrType } from "./RankMgr";


const { ccclass, property } = cc._decorator;

@ccclass
export default class rankingObj extends cc.Component {

    @property(cc.Label)
    label1: cc.Label = null;
    @property(cc.Label)
    label2: cc.Label = null;
    @property(cc.Label)
    label3: cc.Label = null;

    @property(cc.Node)
    bg2:cc.Node = null

    public itemID: number = -1;

    @property({ type: cc.Label })
    label4: cc.Label = null;

    public updateContent1(data: rankMgrType, id: number, initSelectMode: number): void {
        this.itemID = id;
        let curData = data.cityRankInfo[id];
        if(!curData){
            this.node.active = false
            return
        }else{
            this.node.active = true 
        }

        this.label1.string = `${id + 1}`;
        this.label2.string = `${curData.cityName}`;
        this.label3.string = `${curData.grade}位`;
        this.label4.string = `${curData.university}位`;

        let spDi = this.node.getChildByName("spDi");
        spDi.children.forEach((value, index) => {
            value.active = (index == this.itemID);
        })

        this.bg2.active = id%2==1

        this.label1.node.color = id<3? cc.color().fromHEX("#ffffff") : cc.color().fromHEX("#000000");

        // if (this.itemID == 0) {
        //     this.label2.node.color = cc.color().fromHEX("#c42a00");
        //     this.label3.node.color = cc.color().fromHEX("#c42a00");
        //     this.label4.node.color = cc.color().fromHEX("#c42a00");
        // }
        // else if (this.itemID == 1) {
        //     this.label2.node.color = cc.color().fromHEX("#003c6b");
        //     this.label3.node.color = cc.color().fromHEX("#003c6b");
        //     this.label4.node.color = cc.color().fromHEX("#003c6b");
        // }
        // else if (this.itemID == 2) {
        //     this.label2.node.color = cc.color().fromHEX("#005f45");
        //     this.label3.node.color = cc.color().fromHEX("#005f45");
        //     this.label4.node.color = cc.color().fromHEX("#005f45");
        // }
        // else {
        //     this.label2.node.color = cc.color().fromHEX("#000000");
        //     this.label3.node.color = cc.color().fromHEX("#000000");
        //     this.label4.node.color = cc.color().fromHEX("#000000");
        // }

        this.renewShow(initSelectMode);
    }
    renewShow(mode: number) {
        let nums = this.node.getChildByName("nums");
        nums.children.forEach((value, index) => {
            value.active = (index == mode - 1);
        })
    }
}
